package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper {


    @Select("select * from dish where id = #{id}")
    Dish getById(Long id);



    @AutoFill(OperationType.UPDATE)
    void updateStatus(Dish dish);

    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    @AutoFill(OperationType.INSERT)
    void addDish(Dish dish);

    /**
     * 分页查询
     *
     * @param dto
     * @return
     */
    Page<Dish> pageQuery(DishPageQueryDTO dto);

    //  根据id删除菜品
    public int deleteDish(List<Long> dishIds);

    @AutoFill(OperationType.UPDATE)
    void updateDish(Dish dish);


    //根据分类id查询菜品
    @Select("select * from dish where category_id = #{categoryId}")
    List<Dish> getByCategoryId(Long categoryId);

    @Select("select * from dish left join setmeal_dish on dish.id = setmeal_dish.dish_id where setmeal_id = #{setMealId} ")
    List<Dish> getBySetMealId(Long setMealId);


    List<Dish> dishList(Dish dish);

    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);

}
